/**
 * <p>Title: Equipment.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 张小飞
 * @version 1.0
 * <pre>Histroy:
 *          2011-12-14 下午04:37:53  张小飞  Create
 *</pre>
 */
package com.baosight.sczx.common.zm.cInterface.ce;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiColumn;
import com.baosight.iplat4j.core.spring.SpringApplicationContext;
import com.baosight.iplat4j.dao.Dao;
import com.baosight.sczx.common.zm.basetools.StaticTools;

/**
 * <p>Title: Equipment.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 张小飞
 * @version 1.0
 * <pre>Histroy:
 *          2011-12-14 下午04:37:53  张小飞  Create
 *</pre>
 */
public class Equipment {
	
	private static Dao dao = (Dao)SpringApplicationContext.getBean("dao");
	
	/**
	 * 
	 * <p>Function: getEquipmentBlock</p>
	 * <p>Description: 获取设备卡片信息的block</p>
	 * <p>return value:EiBlock</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-12-14下午04:42:32 张小飞
	 * </p>
	 *
	 */
	@SuppressWarnings("rawtypes")
	public static EiBlock getEquipmentBlock(String blockName, Map params){                                                              
		EiBlock block = new EiBlock(blockName);
		
		EiColumn eiColumn = new EiColumn("fdKeyId");
		eiColumn.setType("C");
		block.addMeta(eiColumn);
		
		eiColumn = new EiColumn("fdCode");
		eiColumn.setType("C");
		block.addMeta(eiColumn);
		
		eiColumn = new EiColumn("fdName");
		eiColumn.setType("C");
		block.addMeta(eiColumn);
		
		List<Map> list = new ArrayList<Map>();
		list = getEquipmentList(params);
		block.setRows(list);
		return block;
	}
	
	/**
	 * 
	 * <p>Function: getEquipmentList</p>
	 * <p>Description: 获取设备卡片信息以“List<Map>”形式返回</p>
	 * <p>return value:List<Map></p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-12-14下午04:43:58 张小飞
	 * </p>
	 *
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static List<Map> getEquipmentList(Map params){
		List<Map>  _list = new ArrayList();
		try {
			_list = dao.query("ZMCEEquipmentCard.queryInterface", params);
		} catch (Exception e) {

		}
		return _list;
	}
	
	/**
	 * 
	 * <p>Function: getStandardEquipmentBlock</p>
	 * <p>Description: 获取标准设备信息的block</p>
	 * <p>return value:EiBlock</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2012-1-6下午03:41:07 张小飞
	 * </p>
	 *
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static EiBlock getStandardEquipmentBlock(String blockName, Map params){                                                              
		EiBlock block = new EiBlock(blockName);
		
		EiColumn eiColumn = new EiColumn("fdKeyId");
		eiColumn.setType("C");
		block.addMeta(eiColumn);
		
		eiColumn = new EiColumn("fdToencode");
		eiColumn.setType("C");
		block.addMeta(eiColumn);
		
		eiColumn = new EiColumn("fdName");
		eiColumn.setType("C");
		block.addMeta(eiColumn);
		
		eiColumn = new EiColumn("fdSpecifications");
		eiColumn.setType("C");
		block.addMeta(eiColumn);
		
		eiColumn = new EiColumn("fdModel");
		eiColumn.setType("C");
		block.addMeta(eiColumn);
		
		List<Map> list = new ArrayList<Map>();
		list = dao.query("ZMCEStandredEquipment.queryInterface", params);
		block.setRows(list);
		return block;
	}
	
	/**
	 * 修改状态（使用状态,完好状态）
	 * <p>Function: updateEquipmentStatus</p>
	 * <p>Description: </p>
	 * <p>return value:int</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2012-2-20下午05:28:52 张志芳
	 * </p>
	 *
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static int updateEquipmentStatus(String usingStatus, String intactStatus, String id)	
	{
		Map map = new HashMap();
		map.put("fdUsingType", usingStatus);
		map.put("fdIntactType", intactStatus);
		map.put("fdDate", StaticTools.getDate());
		map.put("fdKeyId", id);
		return dao.update("ZMCEEquipmentCard.changeStatus",map);
	}
	
	/**
	 * 判断某个设备分类下是否有设备存在
	 * <p>Function: hasEquipment</p>
	 * <p>Description: </p>
	 * <p>return value:boolean</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2012-2-21下午04:39:08 张志芳
	 * </p>
	 *
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static boolean hasEquipment(String classId)
	{
		try {
			Map params = new HashMap();
			params.put("fdEquipmentClassId", classId);
			List<Map>  _list  = dao.query("ZMCEEquipmentCard.query", params);
			if(_list.size()>0)
				return true;
			else
				return false;
		} catch (Exception e) {
			
		}
		return true;
	}
	
	/**
	 * 修改状态（使用状态,完好状态）
	 * <p>Function: updateEquipmentType</p>
	 * <p>Description: </p>
	 * <p>return value:int</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2012-2-20下午05:28:52 高强
	 * </p>
	 *
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static int updateEquipmentType(String usingStatus, String departmentId, String department, String engineerId, String engineer,String intactType, String id)	
	{
		Map map = new HashMap();
		map.put("fdUsingType", usingStatus);
		map.put("fdDepartmentId", departmentId);
		map.put("fdDepartment", department);
		map.put("fdEngineeringId", engineerId);
		map.put("fdEngineering", engineer);
		map.put("fdIntactType", intactType);
		map.put("fdDate", StaticTools.getDate());
		map.put("fdEquipmentId", id);
		return dao.update("ZMCEEquipmentCard.dynamic",map);
	}
}
